package tester;

import java.util.Calendar;
import messageWrapper.MessageElement;
import messageWrapper.Message;
import messageWrapper.Packer;

public class MessageWrapperTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ArticleCategory articleCategory = new ArticleCategory();
		articleCategory.setId(11);
		articleCategory.setLevel(50);
		articleCategory.setName("c1");
		BlogArticle blogArticle = new BlogArticle();
		blogArticle.setArticleCategory(articleCategory);
		blogArticle.setContent("content1");
		blogArticle.setId(32);
		blogArticle.setTitle("title1");
		blogArticle.setCreatedTime(Calendar.getInstance());
		blogArticle.setCategory_id(7);
		Packer packer = new Packer("D:\\xml.xml");
		Message messagePack = packer.wrapper(blogArticle);
		String[] list = messagePack.getFieldList();
		for(int i = 0;i<list.length;i++){
			String fieldname= list[i];
			MessageElement te=messagePack.getElement(fieldname);
			String fieldtype = te.getType();
			String fieldvalue = te.getValue().toString();
			System.out.print(fieldname + "  " + fieldtype + "  " + fieldvalue+"\n");
		}

		Message messagePack2=(Message) messagePack.getElement("articleCategory").getValue();
		list = messagePack2.getFieldList();
		for(int i = 0;i<list.length;i++){
			String fieldname= list[i];
			MessageElement te=messagePack2.getElement(fieldname);
			String fieldtype = te.getType();
			String fieldvalue = te.getValue().toString();
			System.out.print(fieldname + "  " + fieldtype + "  " + fieldvalue+"\n");
		}
	}

}
